package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueMapper tbClueMapper;
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;


    @Override
    public int add(ClueTrackRecordVo clueTrackRecordVo) {
        TbClue tbClue = new TbClue();
        TbClueTrackRecord clueTrackRecord = new TbClueTrackRecord();
        BeanUtils.copyProperties(clueTrackRecordVo, tbClue);
        tbClue.setId(clueTrackRecordVo.getClueId());
        BeanUtils.copyProperties(clueTrackRecordVo, clueTrackRecord);
        String createBy = SecurityUtils.getUsername();
        Date nowDate = DateUtils.getNowDate();
        clueTrackRecord.setCreateTime(nowDate);
        clueTrackRecord.setCreateBy(createBy);
        int row1 = tbClueMapper.updateTbClue(tbClue);
        int row2 = tbClueTrackRecordMapper.insertTbClueTrackRecord(clueTrackRecord);
        return row1 & row2;
    }

    @Override
    public List<TbClueTrackRecord> list(Long clueId) {
        return tbClueTrackRecordMapper.list(clueId);
    }
}
